﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GroupManager.Class;
using GroupManager.Resource.CSDL;

namespace GroupManager
{
    public partial class ThongTinHoatDong : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string mdoinhom = Request.QueryString["doinhom"];
            int madoinhom = int.Parse(mdoinhom);
            DataList1.DataSource = LopHoatDong.LayDanhSachHoatDongHienThiTrangChuTheoMaDoiNhom(madoinhom);
            DataList1.DataBind();
        }

        protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
        {
            if (e.CommandName == "Button1")
            {
                dbGroupManagerDataContext db = new dbGroupManagerDataContext();
                int ma = Convert.ToInt32(e.CommandArgument.ToString());
                HoatDong hd = db.HoatDongs.SingleOrDefault(q => q.MaHoatDong == ma);
                hd.TenHoatDong = ((TextBox)DataList1.Items[e.Item.ItemIndex].FindControl("TextBox1")).Text;
                hd.ThangHoatDong =Convert.ToInt32((Convert.ToDateTime((((TextBox)DataList1.Items[e.Item.ItemIndex].FindControl("TextBox2")).Text))).Month);
                hd.NamHoatDong = Convert.ToInt32((Convert.ToDateTime((((TextBox)DataList1.Items[e.Item.ItemIndex].FindControl("TextBox2")).Text))).Year);
                db.SubmitChanges();
                DataList1.DataBind();
 
            }

            if (e.CommandName == "a")
            {
                try
                {
                   
                    int ma = int.Parse(e.CommandArgument.ToString());
                    LopHoatDong.XoaHoatDong(ma);
                    string mdoinhom = Request.QueryString["doinhom"];
                    int madoinhom = int.Parse(mdoinhom);
                    DataList1.DataSource = LopHoatDong.LayDanhSachHoatDongHienThiTrangChuTheoMaDoiNhom(madoinhom);
                    DataList1.DataBind();

                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                }
               // UpdatePanel2.Update();
            }
            
        }
    }
}